
#ifndef JELLY_SHARE_SRC_EMULE_AICH_HASH_TREE_H_
#define JELLY_SHARE_SRC_EMULE_AICH_HASH_TREE_H_

#include "src/emule/aich_hash.h"

namespace jellyfish
{
	namespace emule
	{
		class aich_hash_algorithm;
		class aich_hash_tree
		{
		public:
			aich_hash_tree();
			aich_hash_tree(uint64 size,uint64 block_size,bool is_left_branch);
			void set_size(uint64 size);
			uint64 get_size() const;
			uint64 get_block_size() const;
			aich_hash& get_aich_hash();
			aich_hash_tree* find_hash(uint64 start,uint64 length);
			uint64 create_hash(const uint8* in_buf,uint64 in_buf_length,uint8* out_hash,
				uint64 out_hash_length,aich_hash_tree* tree);
            void SetBlockHash(uint64 nSize, uint64 nStartPos, aich_hash_algorithm* pHashAlg);
		private:
			aich_hash_tree* find_hash(uint64 start,uint64 length,uint8* level);
		private:
			uint64 size_;
			uint64 block_size_;
			bool is_left_branch_;
			aich_hash_tree* left_child_;
			aich_hash_tree* right_child_;
			bool is_hash_valid_;
			aich_hash aich_hash_;
			DISALLOW_COPY_AND_ASSIGN(aich_hash_tree);
		};
	}
}


#endif  // JELLY_SHARE_SRC_EMULE_AICH_HASH_TREE_H_